/* =========================================================
 * ecp.web.component.progress.js
 * =========================================================
 * bootstrap风格进度条
 * Copyright(c) 1998 - 2016 YGSoft.Inc, All Rights Reserved
 * Created by wugang5 on 2016/3/7.
 * ========================================================= */
 
define(["jquery","ecp.utils.i18n"], function($,i18n){
	var template = '<div class="progress" id="progressBar">'
						+'<div class="progress-bar " role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"style="width: 30%;">'
						+	'<span class="sr-only">30%</span>'
						+'</div>'
				  +'</div>';
	/*
	 * 构造进度条
	 * @param container jquery对象
	 */
	function ProgressBar(container){
		if(this instanceof ProgressBar){
			//显示进度条
			this.show = function(){
				container.html(template);
			};
			//隐藏进度条
			this.hide = function(){
				container.empty();
			};
			//设置进度
			this.setPercent = function(percent){
				container.find('#progressBar').children([role="progressbar"]).css("width", percent + "%");
			};
		}else{
			 return new ProgressBar(container);
		}
	};
	(function($) {
		$.fn.ecpProgress = function(option, args){
			return this.each(function(){
				var $this = $(this),
					data = $this.data('progressBar');
				if (!data) {
					$this.data('progressBar', (data = new ProgressBar($this)));
					data.show();
				}
				if(typeof option === 'string'){
					data[option].apply(data, [].concat(args));
				}
			});
		};
	}(jQuery));
	return ProgressBar;
});